package icu.study.netty.client;

import icu.study.protoEntity.MsgProto;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @program: protobuf
 * @description:
 * @author: 1246263205@qq.com
 * @create: 2020-11-19 09:42
 */
public class ClientHandler extends SimpleChannelInboundHandler<MsgProto.Msg> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MsgProto.Msg person) {

    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        for (int i = 0; i < 100; i++) {
            MsgProto.Msg person = null;
            if (i % 2 == 0) {
                person = MsgProto.Msg.newBuilder().setBody("jack" + i).setType(MsgProto.Msg.Type.MESSAGE_GROUP).build();
            } else if (i % 2 == 1) {
                person = MsgProto.Msg.newBuilder().setBody("mark" + i).setType(MsgProto.Msg.Type.FRIEND_ADD).build();
            }
            ctx.channel().writeAndFlush(person);
        }
    }
}
